<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../../css/layui.css" media="all">
		<link href="../../bootstrap-3.3.7-dist/css/bootstrap.css" rel="stylesheet">
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
		<script type="text/javascript" src="../../js/jquery.min.js"></script>
		<link rel="stylesheet" href="../../css/layui.css" media="all">
		<script type="text/javascript" src="../../js/vue.min.js"></script>
	</head>

	<body>
		<div id="app">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;width:97%;">
				<legend>修改上机</legend>
			</fieldset>

			<div class="layui-tab">
				<form id="form" method="post" class="layui-form">
					<div id="set1">
						<!--<div class="layui-tab-item layui-show">
						1. 高度默认自适应，也可以随意固宽。
						<br>2. Tab进行了响应式处理，所以无需担心数量多少。
					</div>-->
						<div class="alert alert-warning alert-dismissible" role="alert" style="width:600px;">
							<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<strong>警告!</strong> 时间和地点一旦修改，原来一起添加的其他班级的上机信息也会进行修改，请仔细核查修改信息
						</div>
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label" style="width:100px;">实验地点</label>
								<div class="layui-input-inline">
									<input type="text" id="expLocation" name="expLocation" class="layui-input" :value="operate.location">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label" style="width:100px;">上课时间</label>
								<div class="layui-input-inline">
									<input type="text" class="layui-input" id="test5" name="beginTime" placeholder="yyyy-MM-dd HH:mm:ss" :value="operate.beginTime">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label" style="width:100px;">下课时间</label>
								<div class="layui-input-inline">
									<input type="text" class="layui-input " id="test6" name="endTime" placeholder="yyyy-MM-dd HH:mm:ss" :value="operate.endTime">
								</div>
							</div>
						</div>
						<!--<div class="layui-input-block">
						<button class="layui-btn" lay-submit="" lay-filter="demo1" @click="add()">立即提交</button>

					</div>-->

					</div>

				</form>
			</div>
		</div>
		<script src="../../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
		<script src="../../layui.js" charset="utf-8"></script>
		<script src="../../js/jquery.cookie.js"></script>
		<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
		<script>
			$.ajax({
				type: "get",
				url: "http://localhost:8080/teacher/experiment/nothing.do",
				async: false,
				dataType: "json",
				data: {
					uid: $.cookie("uid")
				},
				success: function(data) {
					//alert(data.info);
					if(data.info == '404') {
						window.location.href = "../login/teacherlogin.html";
					}
				}
			});

			function GetRequest() {
				var url = location.search; //获取url中"?"符后的字串
				var theRequest = new Object();
				if(url.indexOf("?") != -1) {
					var str = url.substr(1);
					strs = str.split("&");
					for(var i = 0; i < strs.length; i++) {
						theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
					}
				}
				return theRequest;
			}
			var operate;
			var expId;
			var claId;
			//初始化预先值
			function init() {
				var Request = new Object();
				Request = GetRequest(); //接收②方法得来的数组						
				expId = Request["expId"];
				claId = Request["claId"];
				//alert(expId + " " + claId);
				$.ajax({
					type: "get",
					url: "http://localhost:8080/teacher/operate/getoperate.do",
					data: {
						expId: expId,
						claId: claId,
						uid: $.cookie("uid")
					},
					async: false,
					dataType: "json",
					success: function(data) {
						//alert(data);
						//console.log(data);
						operate = data;
					}
				});
			}
			init();

			function mySubmit() {
				add(expId, claId);
			}

			var vue = new Vue({
				el: "#app",
				data: {
					operate: operate
				}
			});

			function add(expId, claId) {
				var expLocation = $("#expLocation").val();
				var beginTime = $("#test5").val();
				var endTime = $("#test6").val();
				//alert(expLocation + " " + beginTime + " " + endTime + "");
				var bool = compareT(beginTime, endTime);
				if(bool == true) {
					/*layer.msg('请确保开始时间小于结束时间', {
						time: 2000,
						btn: ['好的']
					});	*/
					alert("请确保开始时间小于结束时间")
					renturn;
				}
				if(!bool) {
					//alert(expLocation+" "+beginTime+" "+endTime+"");
					$.ajax({
						url: 'http://localhost:8080/teacher/operate/update.do',
						type: 'get',
						data: {
							expLocation: expLocation,
							beginTime: beginTime,
							endTime: endTime,
							expId: expId,
							claId: claId,
							uid: $.cookie("uid")
						},
						dataType: 'json',
						/*contentType: 'application/json',*/
						success: function(result) {
							//alert("success");
						},
						error: function(result) {

						}
					});
				}

			}

			function compareT(beginTime, endTime) {
				//alert("emm");
				var bool = false;
				//年月日与时分秒的分割
				var ymd1 = beginTime.split(" ");
				var ymd2 = endTime.split(" ");
				if(!bool) {
					//年月日的比较
					var d1 = ymd1[0].split("-");
					var d2 = ymd2[0].split("-");
					for(var i = 0; i < d1.length; i++) {
						if(parseInt(d1[i]) > parseInt(d2[i])) {
							bool = true;
							break;
							//alert("false");

						} else {
							continue;
						}
					}
				}
				if(!bool) {
					//时分秒的比较
					var s1 = ymd1[1].split(":");
					var s2 = ymd2[1].split(":");
					for(var i = 0; i < s1.length; i++) {
						if(parseInt(s1[i]) > parseInt(s2[i])) {
							bool = true;
							break;
						}
					}
				}

				return bool;
			}

			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate;

				//日期
				laydate.render({
					elem: '#date'
				});
				laydate.render({
					elem: '#date1'
				});
				//日期时间选择器
				laydate.render({
					elem: '#test5',
					type: 'datetime'
				});
				//日期时间选择器
				laydate.render({
					elem: '#test6',
					type: 'datetime'
				});

				//创建一个编辑器
				var editIndex = layedit.build('LAY_demo_editor');

			});
		</script>

	</body>

</html>